package com.sright.bcard.enterprise.web.controller;

import com.sright.bcard.common.service.share.dto.component.ComponentCufaceMaterialConfigComponentDTO;
import com.sright.bcard.common.service.share.mvcresolver.EnableLoginAuth;
import com.sright.bcard.common.service.share.okhttp.domain.AuthDomain;
import com.sright.bcard.common.service.share.okhttp.domain.AuthFullParam;
import com.sright.bcard.common.share.service.AuthUploadService;
import com.sright.bcard.component.share.service.ComponentConfigWhiteListService;
import com.sright.bcard.component.share.service.ComponentCufaceMaterialConfigComponentService;
import com.sright.common.response.SrightResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/component")
public class ComponentController extends BaseController{

    @Autowired
    private ComponentConfigWhiteListService componentConfigWhiteListService;

    @Autowired
    private ComponentCufaceMaterialConfigComponentService componentCufaceMaterialConfigComponentService;

    @Autowired
    private AuthUploadService authUploadService;

    @GetMapping("/whitelist.json")
    @EnableLoginAuth
    public SrightResponse getComponentConfigWhiteListByEnterprise() {
        return componentConfigWhiteListService.getComponentConfigWhiteListByEnterprise(userContext.getEnterpriseId());
    }

    @PostMapping("/material.json")
    @EnableLoginAuth
    public SrightResponse addOrModify(@RequestBody ComponentCufaceMaterialConfigComponentDTO componentDTO) {
        componentDTO.setEnterpriseId(userContext.getEnterpriseId());
        return componentCufaceMaterialConfigComponentService.addOrModify(componentDTO);
    }

    @PostMapping("/upload.json")
    @EnableLoginAuth
    public SrightResponse upload(@RequestBody AuthDomain authDomain) {
        AuthFullParam authFullParam = new AuthFullParam();
        authFullParam.setAuthDomain(authDomain);
        return authUploadService.auth(authFullParam);
    }

}
